<?PHP


	//** Another new theme ***//

	$GLOBALS['TPL_FORM_ROW_COLOR'] = 'td1';
	class tpl_form {
	
		public static function printform($form){
			
			$row = 'even';
			$output = '';
			
			$fmsg = $form->get_message();
			if(!empty($fmsg)){
				$output .= "<div class='form_container'><div class='row title'>{$GLOBALS['LANG']->lang_formcommon->information}</div><div class='row start'>{$fmsg}</div></div><br />";
			}
			
			foreach($form->get_sections() as $sdata){
				
				$output .= "<div class='form_container'>";
				
				if(!empty($sdata['title']))
					$output .= "<div class='row title'>{$sdata['title']}</div>";
					
				if(!empty($sdata['desc']))
					$output .= "<div class='row start'>{$sdata['desc']}</div>";
					
				if(!empty($sdata['errors']))
					$output .= "<div class='row error'>".implode('<br />',$sdata['errors'])."</div>";
					
				foreach($sdata['fields'] as $fname=>$fdata){
					
					if($fdata['type'] == 'hidden'){
						$output .= "<input type='hidden' name='$fname' value='{$fdata['default']}' />";
						continue;
					}
					
					$label = isset($fdata['label']) ? "<div class='name'><label for='{$fname}'>{$fdata['label']}</label></div>" : '';
					$error = isset($fdata['errors']) ? "<div class='errormsg'>".implode('<br />',$fdata['errors'])."</div>" : '';
					$desc = isset($fdata['desc']) ? "<div class='desc'>{$fdata['desc']}</div>" : '';
					
					$output .= "<div class='row {$row}'><div class='label_container'>{$label}{$error}{$desc}</div>";
					
					switch($fdata['type']){
						case 'password':
							$output .= '&nbsp;&nbsp;&nbsp;&nbsp;'.self::passwordfield($fname,$fdata['default']);
						break;
						case 'checkbox':
							$output .= '&nbsp;&nbsp;&nbsp;&nbsp;'.self::checkboxfield($fname,$fdata['default']);
						break;
						case 'select':
							$output .= '&nbsp;&nbsp;&nbsp;&nbsp;'.self::selectfield($fname,$fdata['options'],$fdata['default']);
						break;
						default:
							$output .= '&nbsp;&nbsp;&nbsp;&nbsp;'.self::textfield($fname,$fdata['default']);
						break;
					}
					
					$output .= "<div style='clear: both'></div></div>";
					
					$row = ($row == 'even' ? 'odd' : 'even');
				}
				
				$output .= "</div><br />";
			}

			return $output;
			
		}
		
		public static function selectfield($fname,$options,$default=''){
			
			$option_html = '';
			foreach($options as $label=>$value){
				$sel = ($value == $default) ? ' selected="true"' : '';
				$option_html .= "<option value='$value'$sel>$label</option>";
			}
			
			return<<<EOV
<select	name='$fname'>
	{$option_html}
</select>
EOV;
		}
		
		public static function checkboxfield($name,$value=''){
			return self::selectfield($name,array($GLOBALS['LANG']->lang_misc->yes=>'true',$GLOBALS['LANG']->lang_misc->no=>''),($value ? 'true' : ''));
		}
		
		public static function textfield($name,$value=''){
			return <<<EOV
<input type='text' name='$name' id='id{$name}' value='$value' class='form_text_norm' onblur="this.className='form_text_norm'" onfocus="this.className='form_text_over'" />
EOV;
		}
		
		public static function passwordfield($name,$value=''){
			return <<<EOV
<input type='password' name='$name' id='id{$name}' value='$value' class='form_text_norm' onblur="this.className='form_text_norm'" onfocus="this.className='form_text_over'" />
EOV;
		}
		
		public static function submitbutton($label){
			return <<<EOV
<input type='submit' value='{$label}' class='form_button_norm' onmouseout="this.className='form_button_norm'" onmouseover="this.className='form_button_over'">
EOV;
		}
		
		public static function button($label,$action,$id=''){
			if(!empty($id))
				$id = "id='$id'";
				
			return <<<EOV
<input type='button' onclick="$action" value='{$label}' $id class='form_button_norm' onmouseout="this.className='form_button_norm'" onmouseover="this.className='form_button_over'">
EOV;
		}
		
		// OLD FORM SHIT STARTS HERE
		
		public static function row_wrapper($html,$fieldname,$label='',$desc='',$options=array(),$error){
			if(!empty($label)) $label = "<label for='inob".$fieldname."'>".$label.'</label>';
			if(!empty($desc)) $desc = "<div class='instructions'>".$desc.'</div>';
			
			if(!empty($error))
				$error = '<div class="small_error_text">'.$error.'</div>';
			
			$GLOBALS['TPL_FORM_ROW_COLOR'] = ($GLOBALS['TPL_FORM_ROW_COLOR'] == 'td2' ? 'td1' : 'td2');
			
			return '<tr><td width="50%" class="'.$GLOBALS['TPL_FORM_ROW_COLOR'].'">'.$label.$desc.$error.'</td><td class="'.$GLOBALS['TPL_FORM_ROW_COLOR'].'">'.$html.'</td></tr>';			
		}
		
		public static function text_password_file($type,$fieldname,$default=''){
			return<<<EOV
<div class='input_container_blur' id='input{$fieldname}'><input type='{$type}' value='{$default}' name='{$fieldname}' id='inob{$fieldname}' class='input_box' onfocus="document.getElementById('input{$fieldname}').className='input_container_focus';" onblur="document.getElementById('input{$fieldname}').className='input_container_blur';" /></div>		
EOV;
		}
		
		public static function checkbox($fieldname,$default=true){
			return tpl_form::select($fieldname,array($GLOBALS['LANG']->lang_formcommon->yes=>'1',$GLOBALS['LANG']->lang_formcommon->no=>''),($default ? 1 : ''));
		}
		
		public static function select($fieldname,$options,$default=''){
			
			$option_html = '';
			foreach($options as $label=>$value){
				$sel = ($value == $default) ? ' selected="true"' : '';
				$option_html .= "<option value='$value'$sel>$label</option>";
			}
			
			return<<<EOV
<select	name='$fieldname'>
	{$option_html}
</select>
EOV;
		}
		
	}
?>